﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CoreEx.Common.Ioc;
using CoreEx.Wcf.Common.Implementation;
using LinFu.IoC.Configuration;
using LinFu.IoC.Interfaces;

namespace CoreEx.Wcf.Common.Implementation
{
    /// <summary>
    /// Provides a default <see cref="ITypeResolver"/> implementation that is 
    /// used if no other <see cref="ITypeResolver"/> service can be found.
    /// </summary>
    [PostProcessor]
    public class TypeResolverPostProcessor : PostProcessorBase<ITypeResolver>
    {
        public override void Process(IServiceRequestResult result)
        {
            if (result.OriginalResult == null)
            {
                if (result.ServiceName == "ServiceContractResolver")
                {
                    result.ActualResult = new ServiceContractResolver();
                }
                if (result.ServiceName == "DataContractResolver")
                {
                    result.ActualResult = new DataContractResolver();
                }
                if (result.ServiceName == "KnownTypeResolver")
                {
                    result.ActualResult = new KnownTypeResolver();
                }
            }                
        }
    }
}